<?php
namespace Tools\Controller;
use Common\Controller\AdminbaseController;


class AdminJobcontentController extends AdminbaseController{


	protected $jobcontent_model;

	public function _initialize(){
		parent::_initialize();
		$this->jobcontent_model=D("ToolsJobcontent");
	}



	// 列表
	public function index(){

		//数量
		$count=$this->jobcontent_model->where()->count();

		//分页
		$page = $this->page($count,10);

		$db_prefix=C('DB_PREFIX');
		$lists = $this->jobcontent_model
			->order("cast(order_date as datetime) desc,orderby asc")
			-> limit($page->firstRow, $page->listRows)
			-> select();

		$this -> assign("page", $page->show('Admin'));
		$this -> assign('lists',$lists);
		$this->display('index');
	}


	//删除
	public function delete(){
		$id=I("get.id",0,'intval');
		$result=$this->jobcontent_model->where(array("id"=>$id))->delete();
		if($result!==false){
			$this->success("删除成功！", U("AdminJobcontent/index"));
		}else{
			$this->error('删除失败！');
		}
	}

	//添加
	public function add(){
		$this->display();
	}

	//添加提交
	public function add_post() {
		$post = I('post.');
		//实例化模型
		$model = M('ToolsJobcontent');
		//增加操作
		$rst = $model -> add($post);
		//判断返回结果
		if($rst!==false){
			//成功
			$this -> success('预约成功！',U('AdminJobcontent/index'));
		}else{
			//失败
			$this -> error('预约失败！',U('AdminJobcontent/add'));
		}
	}
	public function edit()
	{
		$id = I("get.id", 0, 'intval');
		$route = $this->jobcontent_model->where(array('id' => $id))->find();
		$this->assign($route);
		$this->display();
	}

	// url规则编辑提交
	public function edit_post()
	{
		if (IS_POST) {
			if ($this->jobcontent_model->create() !== false) {
				if ($this->jobcontent_model->save() !== false) {
					$this->success("保存成功！", U("AdminJobcontent/index"));
				} else {
					$this->error("保存失败！");
				}
			} else {
				$this->error($this->jobcontent_model->getError());
			}
		}
	}
	/**
	 * 预约管理的批量操作
	 * @param string $type	处理类型 order排序,delete删除
	 */
	public function indexBat($type) {
		//排序
		if ($type == 'order') {
			$order_array = I('post.orderby');
			if ($this->jobcontent_model->saveBatch($order_array, 'id', 'orderby') !== FALSE) {
				$this -> success('排序成功');
			} else {
				$this -> error('排序出错');
			}
		}
		//删除
		if ($type == 'delete') {
			$ids = I('post.ids');
			if ($this->jobcontent_model -> delete(implode(',',$ids)) !== FALSE) {
				$this -> success('删除成功');
			} else {
				$this -> error('删除失败');
			}
		}
  }


}